
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>InnoDB 锁的算法有哪几种 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>InnoDB 锁的算法有哪几种 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">InnoDB中的间隙锁（Gap Lock）主要解决了什么问题？其工作原理是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">间隙锁主要用于防止“幻读”问题。它的工作原理是：当事务对一行数据加锁时，InnoDB不仅锁定该行，还会锁定该行之前和之后的间隙，从而阻止其他事务在这些间隙中插入新记录。</div>
          </div>
          <div class="card-source">来源: 2. 间隙锁（Gap Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是意向锁（Intention Lock），它在InnoDB中扮演什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">意向锁是一种表级锁，用于标记事务打算对表中的某些行加锁。它的主要作用是减少在实际加锁时的冲突和开销，从而提高锁管理的效率。</div>
          </div>
          <div class="card-source">来源: 3. 意向锁（Intention Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">InnoDB是如何实现死锁检测并解决死锁的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">InnoDB使用基于图的死lok检测算法。它会构建一个等待图，并通过检测图中的循环来识别死锁。一旦发现死锁，InnoDB会选择一个事务作为牺牲者，并回滚其操作来解除死锁。</div>
          </div>
          <div class="card-source">来源: 6. 死锁检测</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">InnoDB的行级锁主要分为哪两种类型？请分别说明其功能。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">行级锁主要分为共享锁（S Lock）和排他锁（X Lock）。共享锁允许事务读取数据但不能修改；排他锁允许事务读取和修改数据，并阻止其他事务对该数据行进行任何操作。</div>
          </div>
          <div class="card-source">来源: 1. 行级锁（Record Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">InnoDB的自适应哈希索引（Adaptive Hash Index）是如何提升查询性能的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">InnoDB会监视热点查询，并根据查询模式在内存中动态创建相应的哈希索引。这些哈希索引能用于快速定位数据，从而提高热数据的访问速度并减少磁盘I/O。</div>
          </div>
          <div class="card-source">来源: 4. 自适应哈希索引（Adaptive Hash Index）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">InnoDB行级锁的实现基础是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">InnoDB的行级锁是基于B+树索引实现的。当事务需要修改或读取数据时，InnoDB会锁定相关的索引行。</div>
          </div>
          <div class="card-source">来源: 1. 行级锁（Record Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">请说明意向共享锁（IS）和意向排他锁（IX）分别代表什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">意向共享锁（IS）标记事务将对某些行加共享锁；意向排他锁（IX）标记事务将对某些行加排他锁。</div>
          </div>
          <div class="card-source">来源: 3. 意向锁（Intention Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">尽管间隙锁能防止幻读，但它可能带来什么缺点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">间隙锁的缺点是可能会导致性能问题，因为它锁定的间隙可能会影响其他事务的插入操作。</div>
          </div>
          <div class="card-source">来源: 2. 间隙锁（Gap Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">使用自适应哈希索引有哪些潜在的缺点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">缺点包括：增加了内存使用量，并且在数据更新时哈希索引可能需要重新计算。</div>
          </div>
          <div class="card-source">来源: 4. 自适应哈希索引（Adaptive Hash Index）</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
